home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / idioms.lha / idioms / 2smf.c < prev    next >
C/C++ Source or Header  |  1993-08-08  |  567b  |  26 lines

  1. /* Copyright (c) 1992 by AT&T Bell Laboratories. */
  2. /* Advanced C++ Programming Styles and Idioms */
  3. /* James O. Coplien */
  4. /* All rights reserved. */
  5.  
  6. #include <stdlib.h>
  7.  
  8. class X {
  9. public:
  10.     // ...
  11.     void foo() { fooCounter++;  /* . . . . */ }
  12.     static void printCounts() {
  13.         printf("foo called %d times\en", fooCounter);
  14.     }
  15. private:
  16.     static int fooCounter;
  17. };
  18.  
  19. int X::fooCounter = 0;
  20.  
  21. int main() {
  22.     // printCounts();     // error (unless there really
  23.                        //        is a global function f())
  24.     X::printCounts();  // fine
  25. }
  26.